<?php
	/*
	file ini digunakan untuk mengontrol login apakah user telah sesuai prosedur masuk aplikasi
	*/
class c_kontak extends CI_Controller {

	function __construct(){
		parent::__construct();
		session_start();
		$this->load->model('m_kontak');
		if(!isset($_SESSION[SESSION_USERID])){
			redirect(base_url());
		}

	}//end Login

	function get_action(){
		$task = isset($_POST['task']) ? @$_POST['task'] : $_GET['task'];
		switch($task){
			case "list":
				$this->kontak_list();
			break;
			case "create":
				$this->kontak_create();
			break;
			case "update":
				$this->kontak_update();
			break;
			case "delete":
				$this->kontak_delete();
			break;
			case "search":
				$this->kontak_search();
			break;
			default:
				echo "{ failure : true }";
			break;
		}
	}

	function index(){
		$data["title"]="kontak";
		$data["content"]=$this->load->view('admin/v_kontak_list',$data,TRUE);
		$this->load->view('admin/v_template',$data);
	}

	function kontak_load(){
		$this->load->view('admin/v_kontak_list');
	}


	function listview(){

		$query = isset($_POST['query']) ? $_POST['query'] : "";

		$config['base_url'] = '?c=c_kontak&m=listview';
		$config['total_rows'] = $this->m_kontak->kontak_get_count_rows($query);
		$config['per_page'] = '20';

		$this->pagination->initialize($config);


		$per_page = (integer) (isset($_GET['per_page']) ? $_GET['per_page'] : 0);
		$start = $per_page+1;
		$end = $config['per_page'];


		$data["title"]="AGENDA KEGIATAN";
		$data["menus"]=$this->m_public_function->get_menu_home();
		$data["content"]=$this->m_kontak->kontak_listview($query, $start, $end);
		$data["page"]=$this->pagination->create_links();

		$this->load->view('v_kontak_listview',$data);
	}

	function kontak_add(){
		//$data["title"]="BERITA";
		//$data["content"]=$this->load->view('admin/v_kontak_post',$data,TRUE);
		//$this->load->view('admin/v_template',$data);
		$this->load->view('admin/v_kontak_post');
	}

	function kontak_addedit(){
		$data = array();
		$id = $this->uri->segment(3);
		if($id != false){
			$data['dataDetail'] = $this->m_kontak->getDetail($id);
		}
		$this->load->view('admin/v_kontak_post', $data);
	}

	function kontak_list(){
		$query = $this->input->post('query');
		$pagenum = $_GET['pagenum'];
		$pagesize = $_GET['pagesize'];
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;

		$result=$this->m_kontak->kontak_list($query, $start, $end);
		echo $result;

	}

	function kontak_save(){
		$id = $this->input->post('id');
		$matauang = $this->input->post('matauang');
		$beli = $this->input->post('beli');
		$jual = $this->input->post('jual');
		$tanggal = $this->input->post('tanggal');
		$task = $this->input->post('task');
		$params = array(
			'id'=>$id,
			'data'=>array(
				'matauang'=>$matauang,
				'beli'=>$beli,
				'jual'=>$jual,
				'tanggal'=>$tanggal
			),
			'task'=>$task
		);
		$result = $this->m_kontak->kontak_save($params);
		echo $result;
	}



	function kontak_delete(){
		$id = $this->input->post('id');
		$id = is_numeric($id) ? $id : $id;
		$result = $this->m_kontak->kontak_delete($id);
		echo $result;
	}


	function kontak_search(){

	}

	function kontak_update(){

	}

	function kontak_create(){

	}

}
?>
